package edu.towson.cosc716.tests;
import java.util.Arrays;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import org.junit.Before;
import edu.towson.cosc716.models.InformationAggregator;
import edu.towson.cosc716.models.Invoker;
import edu.towson.cosc716.models.Menu;
import edu.towson.cosc716.models.MenuItem;
import edu.towson.cosc716.models.Table;
import edu.towson.cosc716.models.Order;
import edu.towson.cosc716.models.Customer;
import junit.framework.TestCase;
import java.util.Random;

// TODO: Auto-generated Javadoc
/**
 * The Class ParentTest.
 */
public class ParentTest extends TestCase {	
	
	/** The information aggregator. */
	protected InformationAggregator informationAggregator = new InformationAggregator();
	
	/** The invoker. */
	protected Invoker invoker = new Invoker(informationAggregator);
	
	/** The menu. */
	protected Menu menu = new Menu();
	
	/** The item ids. */
	protected List<Integer> itemIds;

	
	// initialize static class variables
	// ?? informationAggregator.customers.lastCustomerId = 0;

	
	
	/* (non-Javadoc)
	 * @see junit.framework.TestCase#setUp()
	 */
	@Override
	@Before
	protected void setUp() throws Exception {
		
		itemIds = new ArrayList<Integer>();
		
		//  Build Menu and MenuItems
			List<String> miTypes = new ArrayList<String>();
			miTypes.add("Dessert");
			miTypes.add("Dessert");
			miTypes.add("Dessert");
			miTypes.add("Beverage");
			miTypes.add("Beverage");
			miTypes.add("Entree");
			miTypes.add("Entree");
			miTypes.add("Entree");
			miTypes.add("Appetizer");
			miTypes.add("Appetizer");
			
			List<Double> miPrices = new ArrayList<Double>();
			miPrices.add(1.00);
			miPrices.add(1.50);
			miPrices.add(2.00);
			miPrices.add(0.99);
			miPrices.add(1.29);
			miPrices.add(15.00);
			miPrices.add(10.50);
			miPrices.add(25.00);
			miPrices.add(7.50);
			miPrices.add(9.99);
			
			List<Integer> miRating = new ArrayList<Integer>();
			miRating.add(1);
			miRating.add(2);
			miRating.add(3);
			miRating.add(4);
			miRating.add(5);
			miRating.add(1);
			miRating.add(2);
			miRating.add(3);
			miRating.add(4);
			miRating.add(5);
			
			for (int i = 0; i < miTypes.size(); i++) {
				MenuItem menuItem = new MenuItem();
				menuItem.setMiType(miTypes.get(i)); 
				menuItem.setDescription("Test object for " + miTypes.get(i) + " cost " + miPrices.get(i));
				menuItem.setName(miTypes.get(i) + miPrices.get(i));
				menuItem.setCurrentPrice(miPrices.get(i));
				if (i < miRating.size() ) {
					menuItem.addRating(miRating.get(i));
				}
				itemIds.add(menuItem.getItemId());
				menu.addMenuItem(menuItem);
			}
			informationAggregator.menu = menu;
		
		//  Build empty/available Tables and diningRoom, 10 tables each with occupancy of 4/table
			for (int i = 1; i<10; i++) {
				Table table = new Table(4);
				informationAggregator.diningRoom.addTable(table);
			}
		
		//   Create dummy Customers
			ArrayList<String> names = new ArrayList<String>(Arrays.asList("Ron", "Kaden", "Daniel","Farve","OchoCinco","Prince","Sting","Bono","Cher","Santa"));
			ArrayList<Integer> numInParty = new ArrayList<Integer>(Arrays.asList(3,4,2,4,1,3,2,1,4,2));
			ArrayList<Customer> customers = new ArrayList<Customer>();
			for (int i=0; i<10; i++) {
				customers.add(new Customer(names.get(i),numInParty.get(i)));
			}
		
		//  Seat customers at tables (10 customer groups to 10 tables)
			for (int i=0; i<10; i++) {
				Table currTable = informationAggregator.diningRoom.find(i);
				Customer currCustomer = customers.get(i);
				if(!currTable.isOccupied() && currTable.getTableCapacity()>=currCustomer.getPartyCount()) {
					currTable.seatTable(currCustomer.getPartyCount(), currCustomer);
					informationAggregator.diningRoom.updateTable(i, currTable);
				}
			}
		
		//  Create orders for seated customers at all 10 tables - assign on randomly picked menuItem to each
			Iterator<MenuItem> iterator = menu.getMenu();
			int menuItemId = 0;
			while (iterator.hasNext()) {
				menuItemId = iterator.next().getItemId();
			}
			for (int x=0; x<informationAggregator.diningRoom.size(); x++) { // for each of 10 tables being added
				Table currTable = informationAggregator.diningRoom.find(x);
				for (int y=0; y<currTable.getTableOccupancy(); y++) {  // create an order for each person at that table
					informationAggregator.orders.add(new Order(currTable.getTableId(),menuItemId,
						informationAggregator.menu.find(menuItemId).getCurrentPrice()));
				}
			}
	}
}
